package com.atomos.strategy.initialize.velocity
{
	import com.atomos.utils.PointUtils;	
	
	import flash.geom.Point;
	
	import com.atomos.particle.Particle;
	import com.atomos.strategy.initialize.InitializeStrategy;
	import com.atomos.utils.RandomUtils;	

	public class StreamInitializer implements InitializeStrategy
	{
		protected var _pStream : Point;
		protected var _nRandomLength : Number;
		protected var _nRandomDirection : Number;
		
		public function StreamInitializer ( stream : Point, randomLength : Number = 0, randomDirection : Number = 0 )
		{
			_pStream = stream ? stream : new Point();
			_nRandomLength = isNaN( randomLength ) ? 0 : randomLength;
			_nRandomDirection = isNaN ( randomDirection ) ? 0 : randomDirection;
		}
		public function initialize(particle:Particle):void
		{
			var l : Number = _pStream.length + RandomUtils.balance( _nRandomLength );
			var p : Point = _pStream.clone();
			p.normalize( l );
			PointUtils.rotate( p, RandomUtils.balance( _nRandomDirection / 180 * Math.PI ) );

			particle.velocity.x = p.x;
			particle.velocity.y = p.y;
		}
	}
}